package com.example.enjoyarkuix;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class FragmentEntryActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_entry);

        ImageView ivTopBarBack = (ImageView) findViewById(R.id.ivTopBarBack);
        ivTopBarBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        TextView title = (TextView) findViewById(R.id.tvTopBarTitle);
        title.setText("原生Activity");

        findViewById(R.id.viewpager).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(FragmentEntryActivity.this, ViewPagerFragmentActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }
        });

        findViewById(R.id.fragmentmanager).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(FragmentEntryActivity.this, FragmentManagerActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }
        });
        TextView textView = findViewById(R.id.content);
        textView.setText(getparam());
    }
    private String getparam() {
        String paramsStr = "";
        Intent intent = getIntent();
        if (intent == null) {
            Log.e("FragmentEntryActivity", "intent==null: ");
            return paramsStr;
        }

        String params = intent.getStringExtra("params");
        Log.i("FragmentEntryActivity", "params =========: " + params);
        try {
            JSONObject object = new JSONObject(params);
            params = object.getString("params");
            JSONArray array = new JSONArray(params);
            if (array.length() > 1) {
                params = " 接收到的参数：" + params;
            }
        } catch (JSONException e) {
        }
        return params;
    }
}